<div class="row-fluid">
	<div class="row span8 offset2">
    	<form action="<?php echo $this->url('install/default/install_step', array('controller'=>'Install', 'action'=>'installFinish', 'step'=>'step_3')); ?>" method="post" name="install_form" id="install_form">
    	<table class="table table-bordered" style=" margin-bottom:13px; margin-top:8px;">
        	<thead>
        	<tr>
            	<th colspan="2" style="padding-left:5px;"><h4><?php echo $this->translate('DBShop系统安装信息填写'); ?></h4></th>
            </tr>
            </thead>
            <tbody>
            	<tr>
                	<td width="25%" style="text-align:right; font-weight:bold;"><?php echo $this->translate('数据库服务器'); ?><span class="must_add_value">*</span>：</td><td><input type="text" name="dbhost" id="dbhost" value="localhost" class="span6" /><div class="muted"><?php echo $this->translate('数据库服务器地址信息，一般为localhost'); ?></div></td>
                </tr>
            	<tr>
                	<td width="25%" style="text-align:right; font-weight:bold;"><?php echo $this->translate('数据库名称'); ?><span class="must_add_value">*</span>：</td><td><input type="text" name="dbname" id="dbname" value="dbshop" class="span6" /><div class="muted"><?php echo sprintf($this->translate('填写您将要使用的数据库名称（%s该名称必须在数据库中已经存在%s）'), '<font color="#FF0000">','</font>'); ?></div></td>
                </tr>
            	<tr>
                	<td width="25%" style="text-align:right; font-weight:bold;"><?php echo $this->translate('数据库用户名'); ?><span class="must_add_value">*</span>：</td><td><input type="text" name="dbuser" id="dbuser" value="root" class="span6" /><div class="muted"><?php echo $this->translate('连接数据库所使用的用户名'); ?></div></td>
                </tr>
            	<tr>
                	<td width="25%" style="text-align:right; font-weight:bold;"><?php echo $this->translate('数据库密码'); ?>：</td><td><div class="message_one"></div><input type="text" name="dbpasswd" id="dbpasswd" value="123456" class="span6" />&nbsp;<button type="button" class="btn btn-small btn-primary" onclick="check_mysql_connect();" style="margin-bottom:9px;"><i class="icon-retweet icon-white"></i> <?php echo $this->translate('点击测试数据库连接'); ?></button>
                    <div class="muted"><?php echo $this->translate('连接数据库所使用的密码，请确保您输入的密码有效，否则将无法顺利安装'); ?></div></td>
                </tr>
            	<tr>
                	<td width="25%" style="text-align:right; font-weight:bold;"><?php echo $this->translate('数据库连接端口'); ?><span class="must_add_value">*</span>：</td><td><input type="text" name="dbport" id="dbport" value="3306" class="span3" /><div class="muted"><?php echo $this->translate('MySql数据库默认连接端口是3306 如果您的数据库连接端口经过了区别设置，请填写入您的特殊端口'); ?></div></td>
                </tr>
            	<tr>
                	<td width="25%" style="text-align:right; font-weight:bold;"><?php echo $this->translate('数据表前缀'); ?>：</td><td><input type="text" value="dbshop_" readonly="readonly" class="span2" /><div class="muted"><?php echo $this->translate('DBShop系统使用唯一数据表前缀，在同一个数据库中只能安装一套DBShop系统'); ?></div></td>
                </tr>
				<tr>
					<td width="25%" style="text-align:right; font-weight:bold;"><?php echo $this->translate('数据表类型'); ?>：</td><td><div class="innodb_message_one"></div><input type="text" value="InnoDB" readonly="readonly" disabled class="span2" />&nbsp;<button type="button" class="btn btn-small btn-primary" onclick="check_mysql_innodb();" style="margin-bottom:9px;"><i class="icon-random icon-white"></i> <?php echo $this->translate('点击检查InnoDB是否启用'); ?></button>
						<div class="muted">
							<font color="#FF0000"><?php echo $this->translate('MySQL的InnoDB类型必须开启，DBShop系统才能正常安装，有些环境默认没有开启InnoDB，请手动进行开启。'); ?></font>
						</div>
					</td>
				</tr>
            	<tr>
                	<td colspan="2">&nbsp;</td>
                </tr>
            	<tr>
                	<td width="25%" style="text-align:right; font-weight:bold;"><?php echo $this->translate('管理员帐号'); ?><span class="must_add_value">*</span>：</td><td><input type="text" name="adminuser" id="adminuser" value="admin" class="span6" /></td>
                </tr>
            	<tr>
                	<td width="25%" style="text-align:right; font-weight:bold;"><?php echo $this->translate('管理员密码'); ?><span class="must_add_value">*</span>：</td><td><input type="password" name="adminpasswd" id="adminpasswd" value="" class="span6" /></td>
                </tr>
            	<tr>
                	<td width="25%" style="text-align:right; font-weight:bold;"><?php echo $this->translate('再次输入管理员密码'); ?><span class="must_add_value">*</span>：</td><td><input type="password" name="adminpasswd2" id="adminpasswd2" value="" class="span6" /></td>
                </tr>
            	<tr>
                	<td width="25%" style="text-align:right; font-weight:bold;"><?php echo $this->translate('管理员邮箱'); ?><span class="must_add_value">*</span>：</td><td><input type="text" name="adminemail" id="adminemail" value="admin@admin.com" class="span6" /></td>
                </tr>
            	<tr>
                	<td colspan="2">&nbsp;</td>
                </tr>
            	<tr>
                	<td width="25%" style="text-align:right; font-weight:bold;"><?php echo $this->translate('网站名称'); ?><span class="must_add_value">*</span>：</td><td><input type="text" name="webname" id="webname" value="DBShop电子商务系统" class="span6" /></td>
                </tr>
            	<tr>
                	<td width="25%" style="text-align:right; font-weight:bold;"><?php echo $this->translate('系统时区选择'); ?>：</td><td>
                    <select name="webtimezone" id="webtimezone" class="span3">
                     <?php
                     	foreach($this->time_zone_array as $time_array) {
                     		echo '<optgroup label="' . $time_array[0] . '">';
							foreach($time_array[1] as $array_key => $array_value) {
								echo '<option value="' . $array_key . '" '.($array_key == 'Asia/Shanghai' ? 'selected="selected"' : '').'>' . $array_value . '</option>';
							}
                     	}
					 ?>
                    </select>
                    <div class="muted"><?php echo $this->translate('DBShop系统使用时区，中国大陆默认选择上海即可，其他地区可自行选择时区'); ?></div>
                    </td>
                </tr>
                <tr>
                    <td width="25%" style="text-align:right; font-weight:bold;"><?php echo $this->translate('添加地区数据'); ?>：</td><td><input type="checkbox" name="installregion" id="installregion" value="1" checked="checked"/> <?php echo $this->translate('中国'); ?>
                    </td>
                </tr>
                <tr>
                    <td width="25%" style="text-align:right; font-weight:bold;"><?php echo $this->translate('添加演示数据'); ?>：</td><td>
                        <input type="checkbox" name="dbshoptestdata" id="dbshoptestdata" value="1" checked="checked" /> <?php echo $this->translate('演示数据'); ?>
                        <?php if(DBSHOP_TEMPLATE != 'dbmall') echo '<div class="text-error">'.$this->translate('此演示数据首页显示为dbmall模板，请在确定您系统中已有dbmall模板后，将 /data/moduledata/Shopfront/setShop.php 文件中的 DBSHOP_TEMPLATE 和 DBSHOP_TEMPLATE_CSS 对应的值手动设置为 dbmall').'</div>'; ?>
                    </td>
                </tr>
            	<tr>
                	<td width="25%" style="text-align:right; font-weight:bold;"><?php echo $this->translate('是否进行下一步安装'); ?>：</td><td><input type="checkbox" name="dbshopnextstep" id="dbshopnextstep" value="1" checked="checked" onclick="agree_next_step();"/>
                	<div class="text-error"><?php echo sprintf($this->translate('当数据库中已经存在DBShop系统数据表时，安装时会删除已有的DBShop数据表，重新写入DBShop初始化数据表。%s安装操作对同一数据库中的其他系统数据表不会产生任何影响%s。'),'<br><strong>','</strong>'); ?></div>
                	</td>
                </tr>
            </tbody>
        </table>
        <p class="text-center next_step">
        	<a href="<?php echo $this->url('install/default/install_step', array('controller'=>'Install', 'action'=>'installStep', 'step'=>'step_1')); ?>" class="btn btn-large btn-primary"><i class="icon-arrow-left icon-white"></i> <?php echo $this->translate('返回上一步'); ?></a>&nbsp;&nbsp;&nbsp;&nbsp;
        	<button type="submit" class="btn btn-large btn-primary"><i class="icon-arrow-right icon-white"></i> <?php echo $this->translate('继续下一步'); ?></button>
        </p>
        </form>
    </div>
</div>
<script>
//安装信息验证
$(document).ready(function() {
	$("#install_form").validate({
		success : function(label){
			label.addClass('validate_right').text('OK!');
		},
		rules: {
			dbhost: {
				required: true
			},
			dbname: {
				required: true
			},
			dbuser: {
				required: true
			},
			dbport: {
			    required: true
			},
			adminuser: {
				required: true,
				maxlength:30
			},
			adminemail: {
				required: true,
				email: true
			},
            adminpasswd: {
				required: true,
				minlength: 6,
				maxlength: 20
			},
			adminpasswd2: {
				required: true,
				minlength: 6,
				maxlength: 20,
				equalTo: '#adminpasswd'
			},
			webname : {
				required: true
			}
		},
		messages: {
			dbhost: {
				required: "<?php echo $this->translate('请输入数据库服务器地址！'); ?>"
			},
			dbname: {
				required: "<?php echo $this->translate('请输入数据库名称！'); ?>"
			},
			dbuser: {
				required: "<?php echo $this->translate('请输入数据库用户名！'); ?>"
			},
			dbport: {
			    required: "<?php echo $this->translate('请输入数据库连接端口！'); ?>"
			},
			adminuser: {
				required: "<?php echo $this->translate('请输入管理员登录名称！'); ?>",
				maxlength:"<?php echo $this->translate('管理员登录名称最长为30个汉字！'); ?>"
			},
			adminemail: {
				required: "<?php echo $this->translate('请输入管理员电子邮箱！'); ?>",
				email: "<?php echo $this->translate('电子邮箱格式错误！'); ?>"
			},
            adminpasswd: {
				required: "<?php echo $this->translate('请输入管理员密码！'); ?>",
				minlength: "<?php echo $this->translate('至少输入6位密码！'); ?>",
				maxlength: "<?php echo $this->translate('密码最长为20位！'); ?>"
			},
			adminpasswd2: {
				required: "<?php echo $this->translate('请输入管理员确认密码！'); ?>",
				minlength: "<?php echo $this->translate('至少输入6位确认密码！'); ?>",
				maxlength: "<?php echo $this->translate('确认密码最长为20位！'); ?>",
				equalTo: "<?php echo $this->translate('两次输入的密码不一致！'); ?>"
			},
			webname : {
				required: "<?php echo $this->translate('请输入网站名称！'); ?>"
			}
		},
		submitHandler:function(form){
			$.post("<?php echo $this->url('install/default',array('controller'=>'Install', 'action'=>'checkMysqlConnect')); ?>",$('#install_form').formSerialize(),
				function(data){
					if(data == 'true') {
						form.submit();
					} else {
						$('.message_one').html('<div class="alert alert-error"><button data-dismiss="alert" class="close" type="button">×</button><?php echo $this->translate('数据库连接失败，请确定您的数据库已经存在，且您的数据库连接信息正确！'); ?></div>');
						return false;	
					}
				});
		}
	});
});
/**
 * 同意进入下一步安装操作
 */
function agree_next_step() {
	if($("#dbshopnextstep").attr("checked")) {
	    $('.next_step').css('display', '');
	} else {
		$('.next_step').css('display', 'none');
	}
}
/**
 * 检查mysql是否正常连接
 */
function check_mysql_connect() {
	$.post("<?php echo $this->url('install/default',array('controller'=>'Install', 'action'=>'checkMysqlConnect')); ?>",$('#install_form').formSerialize(),
			function(data){
				if(data == 'true') {
					$('.message_one').html('<div class="alert alert-success"><button data-dismiss="alert" class="close" type="button">×</button><?php echo $this->translate('数据库连接成功，可以进行下一步安装操作！'); ?></div>');
				} else {
					$('.message_one').html('<div class="alert alert-error"><button data-dismiss="alert" class="close" type="button">×</button><?php echo $this->translate('数据库连接失败，请确定您的数据库已经存在，且您的数据库连接信息正确！同时请确认您开启了 pdo_mysql 扩展！'); ?></div>');
				}
			});
}

/**
 * 检查mysql是否开启InnoDB类型
 */
function check_mysql_innodb() {
	$.post("<?php echo $this->url('install/default',array('controller'=>'Install', 'action'=>'checkMysqlInnoDB')); ?>",$('#install_form').formSerialize(),
			function(data){
				if(data == 'innodbtrue') {
					$('.innodb_message_one').html('<div class="alert alert-success"><button data-dismiss="alert" class="close" type="button">×</button><?php echo $this->translate('数据库已经启用InnoDB类型，可以进行下一步安装操作！'); ?></div>');
				} else {
					if(data == 'innodbfalse') $('.innodb_message_one').html('<div class="alert alert-error"><button data-dismiss="alert" class="close" type="button">×</button><?php echo $this->translate('MySQL没有启用InnoDB类型，请启用后，再次进行检测！'); ?></div>');
					if(data == 'connectflase') $('.innodb_message_one').html('<div class="alert alert-error"><button data-dismiss="alert" class="close" type="button">×</button><?php echo $this->translate('数据库连接失败，请确定您的数据库已经存在，且您的数据库连接信息正确！'); ?></div>');
				}
			});
}
</script>